
function addMmLightBox(boxData, boxTopic, isElementId) {
	var b = document.body;
	var oldBgScreen = document.getElementById("mm_light_box_screen_2009_02");
	var oldBoxDiv = document.getElementById("mm_light_box_msg_2009_02");
	if(oldBgScreen) {b.removeChild(oldBgScreen);};
	if(oldBoxDiv) {b.removeChild(oldBoxDiv);};
	var bgScreen = document.createElement("div");
	bgScreen.setAttribute("id","mm_light_box_screen_2009_02");
	var box = document.createElement("div");
	box.setAttribute("id","mm_light_box_msg_2009_02");
	if(!boxTopic) boxTopic = "Window";
	var topicP = document.createElement("p");
	topicP.innerHTML = boxTopic;
	var closeP = document.createElement("p");
	closeP.innerHTML = "[Closed]";
	var boxBoby = document.createElement("div");
	box.appendChild(topicP);
	box.appendChild(closeP);
	var boxDataParent = false;
	var d = null;
	if(boxData.length < 100) {
		d = document.getElementById(boxData);
	};
	if(d && isElementId) {
		boxDataParent = d.parentNode;
		d.style.display = "block";
	} else {
		d = document.createElement("div");
		d.innerHTML = boxData;
	};
	boxBoby.appendChild(d);
	box.appendChild(boxBoby);
	b.appendChild(box);
	b.appendChild(bgScreen);
	bgScreen.style.position = "absolute";
	bgScreen.style.backgroundColor = "#666";
	bgScreen.style.top = "0";
	bgScreen.style.left = "0";
	bgScreen.style.width = (document.documentElement.clientWidth + document.documentElement.scrollLeft) + 'px';
	bgScreen.style.height = (document.documentElement.clientHeight + document.documentElement.scrollTop) + 'px';
	bgScreen.style.zIndex = "89990";
	bgScreen.style.opacity = "0.7";
	bgScreen.style.MozOpacity="0.7";
	bgScreen.style.filter = "alpha(opacity=70)";
	box.style.position = "absolute";
	box.style.zIndex = "89998";
	box.style.backgroundColor = "#fff";
	box.style.color = "#000";
	box.style.paddingLeft = "10px";
	box.style.paddingRight = "10px";
	box.style.border = "2px solid #666";
	topicP.style.fontWeight = "bold";
	topicP.style.lineHeight = "30px";
	topicP.style.styleFloat = "left";
	topicP.style.cssFloat = "left";
	topicP.style.float = "left";
	closeP.style.lineHeight = "30px";
	closeP.style.styleFloat = "right";
	closeP.style.cssFloat = "right";
	closeP.style.float = "right";
	closeP.style.cursor = "pointer";
	boxBoby.style.clear = "both";
	boxBoby.style.borderTop = "1px solid #ccf";
	boxBoby.style.padding = "5px 0px 10px 0px";
	if(boxDataParent && isElementId) {
		var boxDivWidth = d.offsetWidth;
	} else {
		var boxDivWidth = d.firstChild.offsetWidth;
	}
	box.style.width = boxDivWidth + "px";
	box.style.left = (document.documentElement.clientWidth / 2 - box.offsetWidth / 2 + document.documentElement.scrollLeft) + "px";
	box.style.top = (document.documentElement.clientHeight / 2 - box.offsetHeight / 2 + document.documentElement.scrollTop) + "px";

	var synSize = function(){
		bgScreen.style.width = (document.documentElement.clientWidth + document.documentElement.scrollLeft) + 'px';
		bgScreen.style.height = (document.documentElement.clientHeight + document.documentElement.scrollTop) + 'px';
		box.style.left = (document.documentElement.clientWidth / 2 - box.offsetWidth / 2 + document.documentElement.scrollLeft) + "px";
		box.style.top = (document.documentElement.clientHeight / 2 - box.offsetHeight / 2 + document.documentElement.scrollTop) + "px";
	}
	var oldOnScroll = window.onscroll;
	if( typeof window.onscroll != 'function' ) {
		window.onscroll = synSize;
	} else {
		window.onscroll = function() {
			oldOnScroll();
			synSize();
		}
	}
	var oldOnResize = window.onresize;
	if( typeof window.onresize != 'function' ) {
		window.onresize = synSize;
	} else {
		window.onresize = function() {
			oldOnResize();
			synSize();
		}
	}
	bgScreen.onclick = function(){
		box.removeChild(topicP);
		box.removeChild(closeP);
		box.removeChild(boxBoby);
		b.removeChild(box);
		b.removeChild(bgScreen);
		if(boxDataParent) {
			d.style.display = "none";
			boxDataParent.appendChild(d);
		}
	};
	closeP.onclick = function() {
		box.removeChild(topicP);
		box.removeChild(closeP);
		box.removeChild(boxBoby);
		b.removeChild(box);
		b.removeChild(bgScreen);
		if(boxDataParent) {
			d.style.display = "none";
			boxDataParent.appendChild(d);
		}
	}
	return boxDataParent;
};

function removeMmLightBox(saveObjId, oldParentObj) {
	var b = document.body;
	var d = document.getElementById(saveObjId);
	if(d) {
		d.style.display = "none";
		if(typeof(oldParentObj) == 'object' && oldParentObj.nodeType == 1) {
			oldParentObj.appendChild(d);
		} else {
			b.appendChild(d);
		}
	}
	var oldBgScreen = document.getElementById("mm_light_box_screen_2009_02");
	var oldBoxDiv = document.getElementById("mm_light_box_msg_2009_02");
	if(oldBgScreen) {b.removeChild(oldBgScreen);}
	if(oldBoxDiv) {b.removeChild(oldBoxDiv);}
};

function addMmLightBoxMsg(boxData, closeAble, redColor, addAjaxLoading, callback) {
	var canClosed = true;
	if(!boxData) {boxData = "Loadding...";};
	if(!closeAble) {canClosed = false;};
	if(!redColor) { redColor = 'blue'; } else { redColor = 'red'; };
	var b = document.body;
	var oldBgScreen = document.getElementById("mm_light_box_screen_msg_2008_10");
	var oldBoxDiv = document.getElementById("mm_light_box_msg_msg_2008_10");
	if(oldBgScreen) {b.removeChild(oldBgScreen);}
	if(oldBoxDiv) {b.removeChild(oldBoxDiv);}
	var bgScreen = document.createElement("div");
	bgScreen.setAttribute("id","mm_light_box_screen_msg_2008_10");
	var boxDiv = document.createElement("div");
	boxDiv.setAttribute("id","mm_light_box_msg_msg_2008_10");
	var textDiv = document.createTextNode(boxData);
	var pTextDiv = document.createElement("div");
	pTextDiv.appendChild(textDiv);
	boxDiv.appendChild(pTextDiv);
	b.appendChild(bgScreen);
	b.appendChild(boxDiv);

	bgScreen.style.position = "absolute";
	bgScreen.style.backgroundColor = "#666";
	bgScreen.style.top = "0";
	bgScreen.style.left = "0";
	bgScreen.style.width = (document.documentElement.clientWidth + document.documentElement.scrollLeft) + 'px';
	bgScreen.style.height = (document.documentElement.clientHeight + document.documentElement.scrollTop) + 'px';
	bgScreen.style.zIndex = "99991";
	bgScreen.style.opacity = "0.7";
	bgScreen.style.MozOpacity="0.7";
	bgScreen.style.filter = "alpha(opacity=70)";

	boxDiv.style.position = "absolute";
	boxDiv.style.zIndex = "99999";
	boxDiv.style.backgroundColor = "#fff";
	boxDiv.style.textAlign = "center";
	boxDiv.style.color = redColor;
	boxDiv.style.lineHeight = "40px";
	boxDiv.style.padding = "30px 50px";
	boxDiv.style.border = "3px solid #666";
	if(addAjaxLoading) {
		boxDiv.style.padding = "30px 50px 30px 90px";
		boxDiv.className = 'ajaxLoading';
	};

	boxDiv.style.left = (document.documentElement.clientWidth / 2 - boxDiv.offsetWidth / 2 + document.documentElement.scrollLeft) + "px";
	boxDiv.style.top = (document.documentElement.clientHeight / 2 - boxDiv.offsetHeight / 2 + document.documentElement.scrollTop) + "px";

	var synSize = function(){
		bgScreen.style.width = (document.documentElement.clientWidth + document.documentElement.scrollLeft) + 'px';
		bgScreen.style.height = (document.documentElement.clientHeight + document.documentElement.scrollTop) + 'px';
		boxDiv.style.left = (document.documentElement.clientWidth / 2 - boxDiv.offsetWidth / 2 + document.documentElement.scrollLeft) + "px";
		boxDiv.style.top = (document.documentElement.clientHeight / 2 - boxDiv.offsetHeight / 2 + document.documentElement.scrollTop) + "px";
	};

	var oldOnScroll = window.onscroll;
	if( typeof window.onscroll != 'function' ) {
		window.onscroll = synSize;
	} else {
		window.onscroll = function() {
			oldOnScroll();
			synSize();
		}
	} ;

	var oldOnResize = window.onresize;
	if( typeof window.onresize != 'function' ) {
		window.onresize = synSize;
	} else {
		window.onresize = function() {
			oldOnResize();
			synSize();
		}
	} ;

	if(canClosed) {
		bgScreen.onclick = function(){
			b.removeChild(boxDiv);
			b.removeChild(bgScreen);
		};
	};

	if('function' == typeof(callback)) {
		callback();
	};
};

function removeMmLightBoxMsg() {
	var b = document.body;
	var bgScreen = document.getElementById("mm_light_box_screen_msg_2008_10");
	var boxDiv = document.getElementById("mm_light_box_msg_msg_2008_10");

	if(boxDiv) {b.removeChild(boxDiv);}
	if(bgScreen) {b.removeChild(bgScreen);}
};

function isEmail(emailString) {
	if(!emailString){return false;}
	if (emailString.charAt(0) == "." || emailString.charAt(0) == "@" || emailString.indexOf('@', 0) == -1|| emailString.indexOf('.', 0) == -1 || emailString.lastIndexOf("@") == emailString.length-1 || emailString.lastIndexOf(".") == emailString.length-1) {return false;}
	return true;
};

function copyToClipboard(txt) {
	if(window.clipboardData) {
		window.clipboardData.clearData();
		window.clipboardData.setData("Text", txt);
	} else if(navigator.userAgent.indexOf("Opera") != -1) {
		window.location = txt;
	} else if (window.netscape) {
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		} catch (e) {
			alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
			return false;
		}
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext = txt;
		str.data = copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid = Components.interfaces.nsIClipboard;
		if (!clip) return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
	};
	alert('下面的内容已经复制到您的剪贴板中.\n' + txt);
};

function addToBookmark(title,url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if(document.all) {
		window.external.AddFavorite(url, title);
	} else if(window.opera && window.print ) {
		return true;
	}
};

jQuery.cookie = function(name, value, options) {
	if (typeof value != 'undefined') {
		options = options || {};
		if (value === null) {
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString();
		}

		var path = options.path ? '; path=' + (options.path) : '';
		var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	} else {
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for (var i = 0; i < cookies.length; i++) {
				var cookie = jQuery.trim(cookies[i]);
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};
